{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "./\\08-exists().ipynb\n",
      "./\\08-find().ipynb\n",
      "./\\08.1-iterdir().ipynb\n",
      "./\\08.2-glob().ipynb\n",
      "./\\08.3-unlink().ipynb\n",
      "./\\08.4-mkdir().ipynb\n",
      "./\\08.5-rmtree().ipynb\n",
      "./\\08.6-walk().ipynb\n",
      "./.ipynb_checkpoints\\08-exists()-checkpoint.ipynb\n",
      "./.ipynb_checkpoints\\08-find()-checkpoint.ipynb\n",
      "./.ipynb_checkpoints\\08.1-iterdir()-checkpoint.ipynb\n",
      "./.ipynb_checkpoints\\08.2-glob()-checkpoint.ipynb\n",
      "./.ipynb_checkpoints\\08.3-unlink()-checkpoint.ipynb\n",
      "./.ipynb_checkpoints\\08.4-mkdir()-checkpoint.ipynb\n",
      "./.ipynb_checkpoints\\08.5-rmtree()-checkpoint.ipynb\n",
      "./.ipynb_checkpoints\\08.6-walk()-checkpoint.ipynb\n"
     ]
    }
   ],
   "source": [
    "# 将find()函数定义成生成器\n",
    "import os\n",
    "def find(top_dir, extension=None):\n",
    "    for root, dirs, files in os.walk(top_dir):\n",
    "        for F in files:\n",
    "            if extension and not F.endswith(extension):\n",
    "                continue\n",
    "            yield f'{root}{os.sep}{F}' # <- yield关键字使find()函数成为一个生成器\n",
    "\n",
    "total_revenue = 0\n",
    "#for F in find('data', extension=\".xlsx\"):\n",
    "for F in find('./', extension=\".ipynb\"):\n",
    "    #total_revenue += extract_revenue(F) # extract_revenue()函数定义于第7.7节\n",
    "    print(F) # 为了在本地进行测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
